import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

public class FileController implements ActionListener {
	FileModel model;
	FileView view;
	
	public FileController(FileModel model, FileView view) {
		this.model = model;
		this.view = view;
		this.view.load.addActionListener(this);
		this.view.save.addActionListener(this);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == view.load) {
			String filename = view.filename.getText();
			try {
				String content = model.load(filename);
				view.content.setText(content);
			} catch(Exception exception) {
				;
			}
		} else {
			String filename = view.filename.getText();
			String new_content = view.content.getText();
			try {
				model.save(filename, new_content);
			} catch(IOException ex) {
				;
			}
		}
	}
}
